﻿using UnityEngine;
using UnityEditor;
using System;
using System.Collections.Generic;

public class NodeTempleteEditorWindow
{
    Dictionary<int, NodeFieldData> NodeFields = new Dictionary<int, NodeFieldData>();

    public int index = 0;

    public bool IsOpen;

    public Texture BG;

    public Rect rect = new Rect(100, 30, 500, 500);
    public void DrawEditorWindow()
    {
        if (IsOpen)
        {
            //GUILayout.BeginArea(rect, BG);
            //DrawNodeTempleteditorWindow(1);
            //GUILayout.EndArea();


        }
    }

    private void DrawNodeTempleteditorWindow(int id)
    {
        GUILayout.BeginVertical();

        GUILayout.BeginHorizontal();
        Debug.Log("11111111111");
        if (GUILayout.Button("Add Field"))
        {
            Debug.Log("2222222222222222");

            NodeFieldData data = new NodeFieldData();
            NodeFields.Add(++index, data);
        }
        GUILayout.EndHorizontal();

        foreach (var item in NodeFields)
        {
            DrawFieldLine(item.Value);
        }
        GUILayout.EndVertical();
    }

    private void DrawFieldLine(NodeFieldData value) 
    {
        GUILayout.BeginHorizontal();
        value.FieldType = GUILayout.TextField(value.FieldType);
        if (!string.IsNullOrEmpty(value.FieldType))
        {
            switch (value.FieldType)
            {
                case "float":
                case "string":
                    if (!string.IsNullOrEmpty(value.FieldValue.ToString()))
                    {
                        value.FieldValue = GUILayout.TextField(value.FieldValue.ToString());
                    }
                    else
                    {
                        value.FieldValue=GUILayout.TextField("请输入数据");
                    }
                    break;

                case "bool":
                    if (!string.IsNullOrEmpty(value.FieldValue.ToString()))
                    {
                        bool result;
                        bool.TryParse(value.FieldValue.ToString(), out result);
                        value.FieldValue = GUILayout.Toggle(result, "test");
                    }
                    else
                    {
                        GUILayout.Toggle(false, "test");
                    }
                    break;

                case "custom":

                    break;
                default:
                    break;
            }
        }
 
        if (GUILayout.Button("Delete"))
        {

        }
        GUILayout.EndHorizontal();
    }
}